﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Spencen.Mobile.UI.Primitives
{
    public class Star : PolygonElement
    {
        public Star()
        {
            NumberOfPoints = 5;
            InnerRadius = 0.4f;
        }

        public int NumberOfPoints { get; set; }
        public float InnerRadius { get; set; }

        protected override Point[] GeneratePoints()
        {
            var points = new List<Point>();
            var outerRadius = Math.Min( Size.Width, Size.Height ) / 2.0f;

            double angleOffset = Math.PI * 2 / NumberOfPoints;
            for ( double angle = 0; angle < Math.PI * 2; angle += angleOffset )
            {
                double innerAngle = angle + angleOffset / 2;

                var outerPoint = new Point(
                    (int)( Math.Sin( angle ) * outerRadius ) + Size.Width / 2,
                    (int)( Math.Cos( angle ) * -outerRadius ) + Size.Height / 2 );

                var innerPoint = new Point(
                    (int)( Math.Sin( innerAngle ) * InnerRadius * outerRadius ) + Size.Width / 2,
                    (int)( Math.Cos( innerAngle ) * -InnerRadius * outerRadius ) + Size.Height / 2 );

                points.Add( outerPoint );
                points.Add( innerPoint );
            }

            return points.ToArray();
        }
    }
}
